// 格式化工具函数

// 格式化日期
export const formatDate = (date) => {
  if (!date) return ''
  const d = new Date(date)
  const year = d.getFullYear()
  const month = String(d.getMonth() + 1).padStart(2, '0')
  const day = String(d.getDate()).padStart(2, '0')
  return `${year}-${month}-${day}`
}

// 格式化金额（保留两位小数）
export const formatPrice = (price) => {
  return Number(price).toFixed(2)
}

// 计算总额
export const calculateTotal = (quantity, unitPrice) => {
  return Number((quantity * unitPrice).toFixed(2))
}

// 生成订单号
export const generateOrderNumber = () => {
  const date = new Date()
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const random = Math.floor(Math.random() * 1000).toString().padStart(3, '0')
  return `FURN${year}${month}${day}${random}`
}
